package com.android.demp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

public class Detail extends Activity{
	private TextView text1;
	private TextView text2;

	private boolean isFirstImage = true;


	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.maindetail);

	text1 = (TextView) findViewById(R.id.TextView01);
	text2 = (TextView) findViewById(R.id.TextView02);
	text2.setVisibility(View.GONE);
	ImageView flipArrow = (ImageView) findViewById(R.id.flipArrow);
	flipArrow.setOnClickListener(new View.OnClickListener() {
	   public void onClick(View view) {
	    if (isFirstImage) {       
	     applyRotation(0, 90);
	     isFirstImage = !isFirstImage;

	    } else {    
	     applyRotation(0, -90);
	     isFirstImage = !isFirstImage;
	    }
	   }
	});  
	ImageView backArrow = (ImageView) findViewById(R.id.backArrow);
	backArrow.setOnClickListener(new View.OnClickListener() {
		   public void onClick(View view) {
			   finish();
		   }
		}); 
	}

	private void applyRotation(float start, float end) {
	// Find the center of image
	final float centerX = text1.getWidth() / 2.0f;
	final float centerY = text1.getHeight() / 2.0f;

	// Create a new 3D rotation with the supplied parameter
	// The animation listener is used to trigger the next animation
	final Flip3dAnimation rotation =
	       new Flip3dAnimation(start, end, centerX, centerY);
	rotation.setDuration(500);
	rotation.setFillAfter(true);
	rotation.setInterpolator(new AccelerateInterpolator());
	rotation.setAnimationListener(new DisplayNextView(isFirstImage, text1, text2));

	if (isFirstImage)
	{
	text1.startAnimation(rotation);
	} else {
	text2.startAnimation(rotation);
	}

	}
	}
